﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AdmLaboratorios.Business;
using AdmLaboratorios.DTO;

namespace AdmLaboratorios
{
    public partial class frmProductoSeleccionVale : Form
    {
        public PartnerDTO Partner { get; set; }
        public ProductoDTO Producto { get; set; }

        public frmProductoSeleccionVale()
        {
            InitializeComponent();
        }

        private void frmProductoSeleccionVale_Load(object sender, EventArgs e)
        {
            FillGrid();
        }

        private void btAceptar_Click(object sender, EventArgs e)
        {
            Seleccionar();
        }

        private void Seleccionar()
        {
            if (gv.SelectedRows.Count == 1)
            {
                Producto = Productos.Get(Convert.ToInt32(gv.SelectedRows[0].Cells["Id"].Value));

                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
        }

        private void btCancelar_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }

        private void txFiltro_TextChanged(object sender, EventArgs e)
        {
            FillGrid();
        }

        private void FillGrid()
        {
            gv.DataSource = null;
            gv.DataSource = Productos.Get(Partner, cbProductosDelPartner.Checked, txFiltro.Text);
        }

        private void cbProductosDelPartner_CheckedChanged(object sender, EventArgs e)
        {
            FillGrid();
        }

        private void gv_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            Seleccionar();
        }



        private void btSeleccionar_Click(object sender, EventArgs e)
        {

        }
    }
}
